<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>深度漫反射实例化demo</title>
  <style>
    body {
      margin: 0;
      overflow: hidden;
    }
    canvas {
      outline: none;
    }
  </style>
</head>
<body>
  <script>
    // 针对深度渲染材质的着色器代码
    const customDepthVertexShader = 
			`
			// instanced
			attribute vec3 instanceOffset;
			attribute float instanceScale;

			#include <common>
			#include <uv_pars_vertex>
			#include <displacementmap_pars_vertex>
			#include <morphtarget_pars_vertex>
			#include <skinning_pars_vertex>
			#include <logdepthbuf_pars_vertex>
			#include <clipping_planes_pars_vertex>

			void main() {

				#include <uv_vertex>

				#include <skinbase_vertex>

				#ifdef USE_DISPLACEMENTMAP

					#include <beginnormal_vertex>
					#include <morphnormal_vertex>
					#include <skinnormal_vertex>

				#endif

				#include <begin_vertex>

				// instanced
				transformed *= instanceScale;
				transformed = transformed + instanceOffset;

				#include <morphtarget_vertex>
				#include <skinning_vertex>
				#include <displacementmap_vertex>
				#include <project_vertex>
				#include <logdepthbuf_vertex>
				#include <clipping_planes_vertex>

			}
			`;

		// 针对漫反射材质的着色器代码
		const customLambertVertexShader =
			`
			#define LAMBERT

			// instanced
			attribute vec3 instanceOffset;
			attribute vec3 instanceColor;
			attribute float instanceScale;

			varying vec3 vLightFront;
			varying vec3 vIndirectFront;

			#ifdef DOUBLE_SIDED
				varying vec3 vLightBack;
				varying vec3 vIndirectBack;
			#endif

			#include <common>
			#include <uv_pars_vertex>
			#include <uv2_pars_vertex>
			#include <envmap_pars_vertex>
			#include <bsdfs>
			#include <lights_pars_begin>
			#include <color_pars_vertex>
			#include <fog_pars_vertex>
			#include <morphtarget_pars_vertex>
			#include <skinning_pars_vertex>
			#include <shadowmap_pars_vertex>
			#include <logdepthbuf_pars_vertex>
			#include <clipping_planes_pars_vertex>

			void main() {

				#include <uv_vertex>
				#include <uv2_vertex>
				#include <color_vertex>

				// vertex colors instanced
				#ifdef USE_COLOR
					vColor.xyz = instanceColor.xyz;
				#endif

				#include <beginnormal_vertex>
				#include <morphnormal_vertex>
				#include <skinbase_vertex>
				#include <skinnormal_vertex>
				#include <defaultnormal_vertex>

				#include <begin_vertex>

				// position instanced
				transformed *= instanceScale;
				transformed = transformed + instanceOffset;

				#include <morphtarget_vertex>
				#include <skinning_vertex>
				#include <project_vertex>
				#include <logdepthbuf_vertex>
				#include <clipping_planes_vertex>

				#include <worldpos_vertex>
				#include <envmap_vertex>
				#include <lights_lambert_vertex>
				#include <shadowmap_vertex>
				#include <fog_vertex>

			}
			`;
  </script>
  <script src="./_instancing_lambert.js" type="module"></script>
</body>
</html>